<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.text.SimpleDateFormat,java.text.DateFormat,java.util.Date"%>
<%@ include file="/WEB-INF/common/taglib.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'orgTree.jsp' starting page</title>
    <link rel="stylesheet" href="${ctx }/static/plugins/JQuery zTree v3.5.15/css/demo.css" type="text/css">
	<link rel="stylesheet" href="${ctx }/static/plugins/JQuery zTree v3.5.15/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="${ctx}/static/js/jquery-1.8.0.min.js"></script>
  	<script type="text/javascript" src="${ctx }/static/plugins/JQuery zTree v3.5.15/js/jquery.ztree.core-3.5.js"></script>
  	<script type="text/javascript" src="${ctx }/static/plugins/JQuery zTree v3.5.15/js/jquery.ztree.excheck-3.5.js"></script>
  	<script src="${ctx}/static/js/orgCommon.js"></script>
  	
  	<script type="text/javascript">  
  	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	///页面加载后初始化zTree数据且默认展开所有节点  
	$(document).ready(function () { 
		var orgData = new Array();
	    var setting = {  
	        check: {  
	            enable: true,  
	            nocheckInherit: false  
	        },  
	        data: {  
	            simpleData: {  
	                enable: true  
	            }  
	        }  
	    };  
	  //ztree用于初始化的静态数据
	    $.ajax({    
		    url:"${ctx}/organization/findOrgList.do",    
		    data:null,    
		    type:"GET",    
		    cache:false,    
		    dataType:"json",
		    async:false, //默认为true 异步 
		    success:function(data) {
		    	$.each(data, function(i, item) {
		    		 var d = {"id":item.orgId,"pId":item.orgPId,"name":item.orgName,"nocheck":true};
		    		 orgData.push(d);
		    	});
		     },    
		     error : function(XMLHttpRequest, textStatus, errorThrown) {
		          
	  		 }    
		});
		$.fn.zTree.init($("#tree"), setting, orgData).expandAll(true); 
	    DynamicUpdateNodeCheck();
	   });  
        
	//过滤节点的机制 直接return node表示不做任何过滤  
	function filter(node) {  
	    return node;  
	}  
        
	///动态设置zTree的所有节点有checkbox  
	function DynamicUpdateNodeCheck() {  
	    var zTree = $.fn.zTree.getZTreeObj("tree");  
	    //根据过滤机制获得zTree的所有节点              
	    var nodes = zTree.getNodesByFilter(filter);  
	    //遍历每一个节点然后动态更新nocheck属性值  
	    for (var i = 0; i < nodes.length; i++) {  
	        var node = nodes[i];  
	        node.nocheck = false; //表示显示checkbox  
	        zTree.updateNode(node);  
	    }  
	}  
          
	function save()
	{
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var nodes = treeObj.getCheckedNodes(true);
		parent.callbackTree(nodes);
		closeOpen();
	}
	function closeOpen(){
   		parent.layer.close(index);
	}
    </script>  
</head>  
<body> 
	<form id="ch">
	<input type="button" value="提交" onclick="save();" />
    <div class="">  
        <div class="zTreeDemoBackground left">  
            <ul id="tree" class="ztree">  
            </ul>  
        </div>  
    </div>  
    </form>
</body>  
</html>  
